// GameObject Base Class
#pragma once
#include <d3d9.h>
#include <d3dx9.h>

// AABB Bounding Box
struct AABB
{
    D3DXVECTOR3 minPos;
    D3DXVECTOR3 maxPos;

    AABB() : minPos(0, 0, 0), maxPos(0, 0, 0) {}
    AABB(const D3DXVECTOR3& minP, const D3DXVECTOR3& maxP)
        : minPos(minP), maxPos(maxP) {}

    bool Intersects(const AABB& other) const
    {
        return (minPos.x <= other.maxPos.x && maxPos.x >= other.minPos.x) &&
               (minPos.y <= other.maxPos.y && maxPos.y >= other.minPos.y) &&
               (minPos.z <= other.maxPos.z && maxPos.z >= other.minPos.z);
    }
};

class GameObject
{
public:
    GameObject();
    virtual ~GameObject();

    virtual void Update(float deltaTime) {}
    virtual void Render(LPDIRECT3DDEVICE9 device) {}
    virtual void Cleanup() {}

    void SetPosition(const D3DXVECTOR3& pos);
    D3DXVECTOR3 GetPosition() const { return m_position; }

    void SetRotation(const D3DXVECTOR3& rot);
    D3DXVECTOR3 GetRotation() const { return m_rotation; }

    void SetScale(const D3DXVECTOR3& scale);
    D3DXVECTOR3 GetScale() const { return m_scale; }

    AABB GetBoundingBox() const { return m_boundingBox; }
    void SetBoundingBox(const AABB& box) { m_boundingBox = box; }
    bool CheckCollision(const GameObject& other) const;

protected:
    D3DXVECTOR3 m_position;
    D3DXVECTOR3 m_rotation;
    D3DXVECTOR3 m_scale;
    AABB m_boundingBox;
};
